 var viewport;
 /*****内容区面板*****/
 var centerPanel;
 /************/
var tabs;
var tabArray =[{name:'方  剂',id:'prescriptions'},{name:'目  录',id:'catalog'},{name:'中  药',id:'traditional'},{name:'条  号',id:'item'}];
var basePath = location.href.substring(0, location.href.lastIndexOf('/'));
var url1 = basePath+'/prescriptions.jsp'
var url02 = basePath+'/catalog.jsp';
var url03 = basePath+'/traditional.jsp';
var url04 = basePath+'/item.jsp';
var centerUrl = basePath+'/content.jsp';
Array.prototype.remove = function(dx)
{
	if(isNaN(dx)||dx>this.length){return false;}
	this.splice(dx,1);
}

 Ext.onReady(function(){

        // NOTE: This is an example showing simple state management. During development,
        // it is generally best to disable state management as dynamically-generated ids
        // can change across page loads, leading to unpredictable results.  The developer
        // should ensure that stable state ids are set for stateful components in real apps.
        Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
	
	//	alert("d3");
	 tabs = new Ext.TabPanel({
        activeTab: 0,
        plain:true,
        defaults:{autoScroll: false,autoHeight: true},
        items:[{
                title: tabArray[1].name,
                el:'catalog_div',
                id:tabArray[1].id,
                autoLoad: {url: url02, params: '',scripts:true}
				
            },{
                title: tabArray[0].name,
                el:'prescription_div',
                id:tabArray[0].id,
				autoLoad: {url: url1, params: '',scripts:true}
            },{
                title: tabArray[2].name,
                el:'herb_div',
                id: tabArray[2].id,
                autoLoad: {url: url03, params: '',scripts:true}

            },{
                title: tabArray[3].name,
                el:'item_div',
                id:tabArray[3].id,
                autoLoad: {url: url04, params: '',scripts:true}
            }
        ]
		});
		centerPanel = new Ext.Panel({
			title: '原文区 ', 
			autoLoad: {url: basePath+'/ca/caContent.jsp', params:{doClass:"content", chapterId:1},scripts:true},
			layout: 'fit',
			region: 'center',
			el: 'content_div',
            autoScroll:true
		});


       viewport = new Ext.Viewport({
            layout:'border',
            items:[
                new Ext.BoxComponent({ // raw
                    region:'north',
                    el: 'north',
					floatable:true,
					collapsible: true,
					margins: '0 0 5 0',
                    height:32
                }),{
                    region:'west',
                    id:'west-panel',
                    title:'',
					collapsible: true,
                    split:true,
                    width: 250,
					collapseMode:'mini',
				//	autoScroll: true,
                    minSize: 185,
                    maxSize: 400,
                    margins:'0 0 0 5',
					items:[tabs]
                  
                },
                centerPanel
                /***{
                	autoScroll: true,
					region: 'center',
					el: 'center_panel',
					autoHeight: true,
					id:'center_panel',
					border: true,layout: 'fit',
					margins: '0 0 5 0',
					items:[centerPanel]
				}**/
             ]
        });
        //默认搜索框 获得焦点
        document.getElementById('sm').focus();
    });
    
/****
id:激活的tab Id
p:参数
刷新传入id的tab
***/
function updateTab(id,p){
    var t = tabs.getItem(id);
	tabs.setActiveTab(t);
	t.getUpdater().update({
	    	url: t.autoLoad.url,
	    	params:p,
	    	scripts:true
		}); 
}
 
 /////////////一下为ext扩展js /////////////////////
 Ext.app.SearchField = Ext.extend(Ext.form.TwinTriggerField, {
    initComponent : function(){
        Ext.app.SearchField.superclass.initComponent.call(this);
        this.on('specialkey', function(f, e){
            if(e.getKey() == e.ENTER){
                this.onTrigger2Click();
            }
        }, this);
    },

    validationEvent:false,
    validateOnBlur:false,
    trigger1Class:'x-form-clear-trigger',
    trigger2Class:'x-form-search-trigger',
    hideTrigger1:true,
    width:180,
    hasSearch : false,

    onTrigger1Click : function(){
        if(this.hasSearch){
            this.el.dom.value = '';
            var o = {start: 0};
            this.store.baseParams = this.store.baseParams || {};
            this.store.baseParams[this.paramName] = '';
            this.store.reload({params:o});
            this.triggers[0].hide();
            this.hasSearch = false;
        }
    },

    onTrigger2Click : function(){
        var v = this.getRawValue();
        if(v.length < 1){
            this.onTrigger1Click();
            return;
        }
        var o = {start: 0};
        this.store.baseParams = this.store.baseParams || {};
        this.store.baseParams[this.paramName] = v;
        this.store.reload({params:o});
        this.hasSearch = true;
        this.triggers[0].show();
    }
});

/////////选择了多个方剂 或者中药///////////////
function comparisonPreMost(url,o){
	   if(!centerPanel)
     {
	     alert('框架页面加载错误！');
	     return;
     }
   
     centerPanel.removeAll();
     centerPanel.getUpdater().update({
      	url: url, 
      	params:o,
      	scripts:true
	});
}


/////////选中了一个方剂 或者中药///////////////
function comparisonPreOne(url,o){
	    if(!centerPanel)
     {
	     alert('框架页面加载错误！');
	     return;
     }
     
     centerPanel.getUpdater().update({
      	url: url, 
      	params: o,
      	scripts:true
	});
}